package cn.wolfcode.service.impl;

import cn.wolfcode.domain.EmpNotice;
import cn.wolfcode.mapper.EmpNoticeMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IEmpNoticeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpNoticeServiceImpl implements IEmpNoticeService {

    @Autowired
    private EmpNoticeMapper empNoticeMapper;


    @Override
    public void save(EmpNotice empNotice) {
        empNoticeMapper.insert(empNotice);
    }

    @Override
    public void delete(Long id) {
        empNoticeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(EmpNotice empNotice) {
        empNoticeMapper.updateByPrimaryKey(empNotice);
    }

    @Override
    public EmpNotice get(Long id) {
        return empNoticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<EmpNotice> listAll() {
        return null;
    }


    @Override
    public PageInfo<EmpNotice> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<EmpNotice> empNotices = empNoticeMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<EmpNotice>(empNotices);
    }

    @Override
    public void updateStatu(Long id, Long userId) {
       EmpNotice empNotice=empNoticeMapper.selectBytwoId(id,userId);
        empNotice.setReaded(true);
        empNoticeMapper.updateStatu(empNotice);
    }

    @Override
    public int selectUnRead(Long id, boolean b) {
        return empNoticeMapper.selectUnRead(id,b);
    }
}
